package com.itheima.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.pojo.Checkitem;
import com.itheima.service.CheckitemService;
import com.itheima.support.PageResult;
import com.itheima.support.QueryPageBean;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
public class CheckitemController {
    @DubboReference
    private CheckitemService checkitemService;

    @PostMapping("/save")
    public Boolean save(@RequestBody Checkitem checkitem){
       return checkitemService.saveorUpdateData(checkitem);
    }

    @GetMapping("/findAll")
    public List<Checkitem> findAll(){
        return checkitemService.list();
    }

    @PostMapping("/findByPage")
    @PreAuthorize("hasAuthority('admin')")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
        return checkitemService.findByPage(queryPageBean);
    }

    @GetMapping("/delete/{id}")
    public Boolean delete(@PathVariable("id") Integer id){
       return checkitemService.removeById(id);
    }
}
